import { createRouter, createWebHashHistory } from 'vue-router'
import { routes } from './constRoute'
import { getItem } from '@/utils/storage/session.js'
const router = createRouter({
  history: createWebHashHistory(),
  routes
})
router.beforeEach((to, from, next) => {
  // console.log('to', to)
  // console.log('from', from)
  const token = getItem('token')
  if (to.path !== '/login') {
    if (token) {
      next()
    } else {
      next('/login')
    }
  } else {
    next()
  }
})
export default router
